package cn.zhl.word;

import org.apache.poi.hwpf.extractor.WordExtractor;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-03-20 11:29
 **/
public class DocUtil {
	/**
	 * 读取doc文件内容
	 * <p>
	 * 想要读取的文件对象
	 *
	 * @return 返回文件内容
	 * @throws IOException
	 */
	public static String doc2String(FileInputStream fs) throws IOException {
		StringBuilder result = new StringBuilder();
		WordExtractor re = new WordExtractor(fs);
		result.append(re.getText());
		re.close();
		return result.toString();
	}

	public static String doc2String(File file) throws IOException {
		return doc2String(new FileInputStream(file));
	}

	public static void main(String[] args) {
		File file = new File("C:\\Users\\Administrator\\Documents\\WeChat Files\\maopaigaoshou\\FileStorage\\File\\2020-03\\疫情防控知识答题(修改）(2).doc");
		try {
			String s = doc2String(file);

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
		}
	}
}
